//
//  FTTextView.m
//  FashionTech
//
//  Created by JackieYip on 16/5/30.
//  Copyright © 2016年 mondial-d. All rights reserved.
//

#import "FTTextView.h"
//#import <objc/runtime.h>

static NSString *const FTPlaceholderColorKeyPath = @"_placeholderLabel.textColor";
@implementation FTTextView

//+ (void)initialize
//{
//    unsigned int count;
//    Ivar *ivars = class_copyIvarList(self, &count);
//    for (int i = 0; i < count; i++) {
//        Ivar ivar = *(ivars + i);
//        FTLog(@"%s", ivar_getName(ivar));
//    }
//}

- (instancetype)init
{
    if (self = [super init]) {
        [self setup];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

- (void)setup
{
    // set cursor color
    self.tintColor = [UIColor blackColor];
    [self resignFirstResponder];
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self setup];
}

- (BOOL)becomeFirstResponder
{
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
        [self setValue:[UIColor blackColor] forKeyPath:FTPlaceholderColorKeyPath];
    }
    return [super becomeFirstResponder];
}

- (BOOL)resignFirstResponder
{
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
        [self setValue:[UIColor grayColor] forKeyPath:FTPlaceholderColorKeyPath];
    }
    return [super resignFirstResponder];
}

@end
